<?php
/**
 * Created by PhpStorm.
 * User: gesangdianzi
 * Date: 2017/8/27
 * Time: 10:47
 */

namespace utils;


use yii\helpers\Url;

class Comm
{
    public static $sex = ['0'=>'未知','1'=>'男','2'=>'女'];
    public static function v(){
        return '20180207006';
    }

    public static function minPic($pic){
        if(preg_match('/\.jpeg/',$pic)){
            return $pic;
        }
        return $pic.'_260x260.jpg';
    }

    public static $key = 'URLJKEY';
    public static function J($url){
        $key = self::JKey($url);
        \Yii::$app->cache->set($key,$url);
        return $key;
    }

    public static function G($key){
        return \Yii::$app->cache->get($key);
    }
    private static function JKey($url){
        return md5($url.self::$key);
    }

    /**
     * @author       :   DuYongGao
     * @name         :   isWx
     * @description  :判断客户端是否微信
     * @return bool
     */
    public static function isWx(){
        if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
            return true;
        }
        return false;
    }

    public static function isMobile(){
        if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) {
            return true;
        }
        if (isset ($_SERVER['HTTP_VIA'])) {
            return true;
        }

        if (isset ($_SERVER['HTTP_USER_AGENT'])) {
            $clientkeywords = array ('nokia',  'sony','ericsson','mot',
                'samsung','htc','sgh','lg','sharp',
                'sie-','philips','panasonic','alcatel',
                'lenovo','iphone','ipod','blackberry',
                'meizu','android','netfront','symbian',
                'ucweb','windowsce','palm','operamini',
                'operamobi','openwave','nexusone','cldc',
                'midp','wap','mobile'
            );
            // 从HTTP_USER_AGENT中查找手机浏览器的关键字
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){
                return true;
            }
        }

        if (isset ($_SERVER['HTTP_ACCEPT'])) {
            // 如果只支持wml并且不支持html那一定是移动设备
            // 如果支持wml和html但是wml在html之前则是移动设备
            if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
                return true;
            }
        }

        return false;
    }

    public static function Jump($gid,$aid,$pic,$title){
//        $url = 'http://quan007.com/jump/162784/'.$gid;
//        $url = 'http://faqua.cn/jump/62475/'.$gid;
        $url = Url::to(['search/jump',"gid"=>$gid,'aid'=>$aid,'pic'=>$pic,'title'=>$title]);
        return $url;
    }
}